package com.sky.mapper;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     * 清空购物车
     * @param shoppingCart
     */
    @Delete("delete from sky_take_out.shopping_cart where user_id = #{userId}")
    void DeleteCart(ShoppingCart shoppingCart);

    /**
     * 用于动态sql 来查询购物车里的数据
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> Query(ShoppingCart shoppingCart);

    /**
     * 根据购物车的id来更新相应的购物车中商品等的数量数据
     * @param shoppingCart
     */
    @Update("update sky_take_out.shopping_cart set number = #{number} where id = #{id}")
    void UpdateNumberById(ShoppingCart shoppingCart);

    /**
     * 插入购物车数据
     * @param shoppingCart
     */
    @Insert("insert into sky_take_out.shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time, number) " +
            "values (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount},#{createTime},#{number})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 在购物车中删除内容
     * @param shoppingCartDTO
     */
    void deleteItem(ShoppingCartDTO shoppingCartDTO);

    /**
     * 批量的插入购物车的对象内容
     * @param shoppingCartList
     */
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
